package com.cakeclient.Model;


import java.util.Stack;

public class Address {
    private Integer idDB;
    private String line1;
    private String line2;
    private String line3;
    private String line4;
    private String city;
    private String postalCode;
    private String country;

    public Address() {
        //rien
    }

    public Address(com.cakeclient.clientsoap.contract.Address deliveryAddress) {
        this.line1 = deliveryAddress.ligne1;
        this.line2 = deliveryAddress.ligne2;
        this.line3 = deliveryAddress.ligne3;
        this.line4 = deliveryAddress.ligne4;
        this.city = deliveryAddress.city;
        this.postalCode = ((Integer) deliveryAddress.postalCode).toString();
        this.country = deliveryAddress.country;
    }

    public String getLine3() {
        return line3;
    }

    public void setLine3(String line3) {
        this.line3 = line3;
    }

    public String getLine4() {
        return line4;
    }

    public void setLine4(String line4) {
        this.line4 = line4;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public Address(String line1, String line2, String line3, String line4, String city, String postalCode, String country) {
        this.line1 = line1;
        this.line2 = line2;
        this.line3 = line3;
        this.line4 = line4;
        this.city = city;
        this.postalCode = postalCode;
        this.country = country;
    }

    public String getPostalCode() {
        return postalCode;
    }

    public void setPostalCode(String postalCode) {
        this.postalCode = postalCode;
    }

    public Integer getIdDB() {
        return idDB;
    }

    public void setIdDB(Integer idDB) {
        this.idDB = idDB;
    }

    public String getLine1() {
        return line1;
    }

    public void setLine1(String line1) {
        this.line1 = line1;
    }

    public String getLine2() {
        return line2;
    }

    public void setLine2(String line2) {
        this.line2 = line2;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String toUriComponent() {

        return toString().replace(' ', '+');
    }

    @Override
    public String toString() {
        Stack<String> builder = new Stack<String>();
        if (line1 != null && !line1.isEmpty()) {
            builder.push(line1);
        }
        if (line2 != null && !line2.isEmpty()) {
            builder.push(line2);
        }
        if (line3 != null && !line3.isEmpty()) {
            builder.push(line3);
        }
        if (line4 != null && !line4.isEmpty()) {
            builder.push(line4);
        }
        String result = "";
        while (!builder.isEmpty()) {
            result += builder.pop();
            result += ", ";
        }
        return (result + city + " " + postalCode.toString() + " " + country);
    }


}
